package controller.menus;

import gui.menus.MenuLevelActions;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import javax.swing.JMenuItem;

public class BackLevelMenuItemController implements ActionListener,
		PropertyChangeListener {

	private final JMenuItem backItem;
	private final MenuLevelActions actionHandler;

	public BackLevelMenuItemController(JMenuItem backItem,
			MenuLevelActions actionHandler) {
		this.backItem = backItem;
		this.actionHandler = actionHandler;
		this.actionHandler.addCurrentLevelPropertyChangeListener(this);
		this.backItem.setEnabled(actionHandler.canBackLevel());
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		this.actionHandler.actionBackLevel();
	}

	/**
	 * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
	 */
	@Override
	public void propertyChange(PropertyChangeEvent evt) {
		this.backItem.setEnabled(actionHandler.canBackLevel());
	}

}
